import cv2
import selectivesearch

# img = skimage.data.astronaut()
img = cv2.imread("ch.jpeg")

img_lbl, regions = selectivesearch.selective_search(img, scale=500, sigma=0.9, min_size=10)

print(regions)

width = img.shape[1]
height = img.shape[0]
print("width:", str(width), " height:" + str(height))

for reg in regions:
    rects = reg['rect']
    print(rects)
    # if rects[3] > height / 2 and rects[3] < (height * 3.0/ 4):
    cv2.rectangle(img, (rects[0], rects[1]), (rects[0] + rects[2], rects[1] + rects[3]), (0, 0, 255), thickness=1)

cv2.imshow("x", img)
cv2.waitKey(100000)

# regions[:10]

# =>
# [{'labels': [0.0], 'rect': (0, 0, 15, 24), 'size': 260},
#  {'labels': [1.0], 'rect': (13, 0, 1, 12), 'size': 23},
#  {'labels': [2.0], 'rect': (0, 15, 15, 11), 'size': 30},
#  {'labels': [3.0], 'rect': (15, 14, 0, 0), 'size': 1},
#  {'labels': [4.0], 'rect': (0, 0, 61, 153), 'size': 4927},
#  {'labels': [5.0], 'rect': (0, 12, 61, 142), 'size': 177},
#  {'labels': [6.0], 'rect': (7, 54, 6, 17), 'size': 8},
#  {'labels': [7.0], 'rect': (28, 50, 18, 32), 'size': 22},
#  {'labels': [8.0], 'rect': (2, 99, 7, 24), 'size': 24},
#  {'labels': [9.0], 'rect': (14, 118, 79, 117), 'size': 4008}]
